package com.xiaoshuidi.cloud.module.bpm.controller.admin.reserveapartmentconfig;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.bpm.controller.admin.reserveapartmentconfig.vo.ReserveApartmentConfigPageReqVO;
import com.xiaoshuidi.cloud.module.bpm.controller.admin.reserveapartmentconfig.vo.ReserveApartmentConfigPageRespVO;
import com.xiaoshuidi.cloud.module.bpm.controller.admin.reserveapartmentconfig.vo.SetupReserveNumReqVO;
import com.xiaoshuidi.cloud.module.bpm.service.reserveapartmentconfig.ReserveApartmentConfigService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 门店预约配置 前端控制器
 * </p>
 *
 * @author hans.zhang
 * @since 2023-12-01
 */
@Slf4j
@RestController
@RequestMapping("/bpm/reserve-apartment-config")
@RequiredArgsConstructor
public class ReserveApartmentConfigController {

    private final ReserveApartmentConfigService reserveApartmentConfigService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    @PreAuthorize("@ss.hasPermission('bpm:reserve-apartment-config:query')")
    public CommonResult<PageResult<ReserveApartmentConfigPageRespVO>> getPage(ReserveApartmentConfigPageReqVO reqVO){
        return reserveApartmentConfigService.getPage(reqVO);
    }

    @PostMapping("/setup-reserve-num")
    @Operation(summary = "设置预约人数")
    @PreAuthorize("@ss.hasPermission('bpm:reserve-apartment-config:update')")
    public CommonResult<Boolean> setupReserveNum(@RequestBody @Valid SetupReserveNumReqVO reqVO){
        return reserveApartmentConfigService.setupReserveNum(reqVO);
    }

    @GetMapping("/get-reserve-num")
    @Operation(summary = "预约人数回显")
    @PreAuthorize("@ss.hasPermission('bpm:reserve-apartment-config:query')")
    public CommonResult<Map<Integer, Integer>> getReserveNum(@NonNull Long apartmentId){
        return CommonResult.success(reserveApartmentConfigService.getReserveNum(apartmentId));
    }
}
